package com.rms.server.Controller;

import com.rms.server.DTO.OrderRequest;
import com.rms.server.Service.OrderService;
import com.rms.server.VO.DailySalesProfitResponse;
import com.rms.server.VO.OrderResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@RestController
@RequestMapping("/api/orders")
@Tag(name = "订单管理", description = "订单管理相关接口")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/create")
    @Operation(summary = "创建订单", description = "根据菜品 ID 和数量创建订单")
    public ResponseEntity<OrderResponse> createOrder(@RequestBody List<OrderRequest> orderRequests) {
        OrderResponse orderResponse = orderService.createOrder(orderRequests);
        return ResponseEntity.ok(orderResponse); // 返回订单信息、订单详情和库存变化
    }
//
@GetMapping("/sales-profit")
@Operation(summary = "获取销售额和利润", description = "根据指定日期范围获取每日销售额和利润及总销售额和总利润")
public ResponseEntity<DailySalesProfitResponse> getSalesProfit(
        @RequestParam("startDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
        @RequestParam("endDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {

    // 调用 service 层计算销售额和利润
    DailySalesProfitResponse response = orderService.calculateSalesProfit(startDate, endDate);

    // 返回响应结果
    return ResponseEntity.ok(response);
}

}